// components/my-form/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        showForm: {
            type: Boolean
        },
        formTitle: {
            type: String
        },
        form: {
            type: Object
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        dIsShow: false,
        dForm: {},
    },

    observers: {
        showForm: function (showForm) {
            this.setData({
                dIsShow: showForm
            });
        },
        form: function (form) {
            this.setData({
                dForm: form
            });
        },
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // 关闭弹框
        onClose() {
            this.setData({
                dIsShow: false
            })
        },
        // 提交数据
        onSubmit() {
            this.triggerEvent('OnSubmit', this.data.dForm);
        },
        // 表单赋值
        bindInputChange(e) {
            let index = e.currentTarget.dataset.index;
            let dForm = this.data.dForm;
            dForm.props[index].value =  e.detail.value
            this.setData({
                dForm
            })
        },
        // 下拉选择框改变
        bindPickerChange(e) {
            let index = e.currentTarget.dataset.index;
            let dForm = this.data.dForm;
            dForm.props[index].value = e.detail.value
            this.setData({
                dForm
            })
        },
        // 单选框改变
        bindRadioChange(e) {
            let index = e.currentTarget.dataset.index;
            let dForm = this.data.dForm;
            dForm.props[index].value = e.detail.value
            this.setData({
                dForm
            })
        }
    }
})